﻿@using System.Data
@using STX.Domain
@model STX.Admin.Models.BizExpense.EditModel
<form class="pageForm addpage" action="@Url.Action("SaveAddPayinfos")" method="post" id="editfinanceform">
    <div style=" height:100%; width:100%; overflow:hidden" class="verticalSplitContainer">
        <div class="pageFormContent" ratio="*">
            <input type="hidden" value="@Model.Id" name="Id" />
            <div class="inputActivityDiv">
                <table style="width:100%">
                    <tr>    
                        <td width="15%">活动名称：</td>
                        <td width="35%">@Model.Name</td>
                        <td width="15%">所属项目：</td>
                        <td width="35%">@Model.ProjectName
                        </td>
                    </tr>
                    
                    <tr>    
                        <td width="15%">合同报价：</td>
                        <td width="35%">@Model.TotalQuotation</td>
                        <td width="15%">增减情况：</td>
                        <td width="35%">@Model.IncreaseOrDecrease</td>
                    </tr>
                </table>
                @{
                    var result = from s in Model.ActivityItems
                        group s by s.SupplierId
                        into g
                        select new
                        {
                            g,
                            g.Key
                        };
                    int i = 0;
                }

                @foreach (var item in result)
                {
                    var entity = item.g.FirstOrDefault();
                    if (entity == null)
                    {
                        continue;
                    }
                    decimal finalPay = 0;
                    var payTime = DateTime.Now;
                    var payEntity = Model.PayInfos.FirstOrDefault(o => o.SupplierId == entity.SupplierId);
                    if (payEntity != null)
                    {
                        finalPay = payEntity.FinalPay;
                        payTime = payEntity.PayTime;
                    }
                    <div class="materialitem">
                        <h4 style="background: #c0c0c0; padding: 6px;">供应商：@entity.BizSupplier.Name</h4>
                        <table style="width: 100%" cellpadding="5" cellspacing="0" class="grewtable">
                            <tr>
                                <td width="30%">物料名称</td>
                                <td width="15%">报价</td>
                                <td width="55%">成本</td>
                            </tr>
                            @foreach (var activityItem in item.g)
                            {
                                <tr>
                                    <td>@activityItem.Name</td>
                                    <td>@(activityItem.QuotationPrice*activityItem.Numb)</td>
                                    <td>@(activityItem.FinanceCostPrice*activityItem.Numb)</td>
                                </tr>
                            }
                            <tr>
                                <td>合计</td>
                                <td>@(item.g.Sum(o=>o.QuotationPrice*o.Numb))</td>
                                <td>@(item.g.Sum(o => o.FinanceCostPrice * o.Numb))&nbsp;&nbsp;
                                    实际支付:<input name="PayInfos[@i].FinalPay" class="textInput" type="text" size="15" value="@finalPay" alt=""/> 
                                    支付时间：<input name="PayInfos[@i].PayTime" class="textInput datetime" type="text" size="10" value="@payTime.ToString("yyyy-M-d")" />
                                    <input type="hidden" value="@Model.Id" name="PayInfos[@i].ActivityId" />
                                    <input type="hidden" value="@entity.SupplierId" name="PayInfos[@i].SupplierId" />
                                </td>
                            </tr>
                        </table>
                    </div>
                    i++;
                }
            </div>
        </div>

        <div class="formBar" ratio="#30">
            <ul>
                <li><div class="simplebutton"><div class="r"><button type="button" class="submit">提交</button></div></div></li>
            </ul>
        </div>
    </div>
</form>